<template>
<div class="task-detail">
  <div class="header">
    <div class="back-btn" @click="$router.back()">
      <i class="el-icon-back"></i>
    </div>
    <div style="flex: 1;text-align: left;margin-left: 10px">
      <el-input v-if="titleEditMode" @blur="saveTask" v-model="task.title" size="small" style="width: 200px;"></el-input>
      <span v-else @click="titleEditMode=true">{{task.title}}</span>
    </div>
    <el-button size="small" @click="saveTask"  type="primary">更新</el-button>
  </div>
  <div class="content">
    <!-- 富文本编辑器组件 -->
    <div class="flex">
      <quill-editor class="editor" v-model="task.content" :options="editorOption" ref="myQuillEditor"></quill-editor>
      <div class="right-panel">
        <div class="panel-container">
          <div class="panel">
            <div class="panel-title">
              <i class="el-icon-document-checked" style="margin-right: 10px"></i><span>任务清单</span>
            </div>
            <div class="panel-content">
              <div class="check-item">
                <el-checkbox>测试1</el-checkbox>
              </div>
              <div class="check-item">
                <el-checkbox>测试2</el-checkbox>
              </div>
              <div class="check-item">
                <el-checkbox>测试3</el-checkbox>
              </div>
            </div>
          </div>
          <div class="panel">
            <div class="panel-title">
              <span>前置任务</span>
            </div>
            <div class="panel-content">
              <span>任务名</span>
              <el-button type="text" size="small">查看</el-button>
            </div>
          </div>
          <div>
            <iframe src="//player.bilibili.com/player.html?aid=474676934&bvid=BV1GK411S7s8&cid=877591396&page=1" scrolling="no" border="0" frameborder="no" framespacing="0" allowfullscreen="true" width="100%" height="230px"> </iframe>
          </div>
        </div>
      </div>

    </div>
    <div class="footer">
      <span>Hello World</span>
    </div>
  </div>

</div>
</template>

<script>
import {getTaskDetail, updateTask} from "@/api";
import hljs from 'highlight.js'
import 'highlight.js/styles/vs2015.css'
const fonts = [
  'SimSun',
  'SimHei',
  'Microsoft-YaHei',
  'KaiTi',
  'FangSong'
]
export default {
  name: "TaskDetail",
  data(){
    return {
      titleEditMode:false,
      task:{id:this.$route.params.id},
      editorOption:{
        placeholder:'',
        modules:{
          toolbar:{
            container:[
              ['bold', 'italic', 'underline', 'strike'], // 加粗 斜体 下划线 删除线 -----['bold', 'italic', 'underline', 'strike']
              [{ color: [] }, { background: [] }], // 字体颜色、字体背景颜色-----[{ color: [] }, { background: [] }]
              [{ align: [] }], // 对齐方式-----[{ align: [] }]
              [{ font: fonts }], // 字体种类-----[{ font: [] }]
              [{ header: [1, 2, 3, 4, 5, 6, false] }], // 标题
              [{ direction: 'ltl' }], // 文本方向-----[{'direction': 'rtl'}]
              [{ direction: 'rtl' }], // 文本方向-----[{'direction': 'rtl'}]
              [{ indent: '-1' }, { indent: '+1' }], // 缩进-----[{ indent: '-1' }, { indent: '+1' }]
              [{ list: 'ordered' }, { list: 'bullet' }],
              // 有序、无序列表-----[{ list: 'ordered' }, { list: 'bullet' }]
              [{ script: 'sub' }, { script: 'super' }], // 上标/下标-----[{ script: 'sub' }, { script: 'super' }]
              ['blockquote', 'code-block'], // 引用  代码块-----['blockquote', 'code-block']
              ['clean'], // 清除文本格式-----['clean']
              ['link', 'image', 'video'] // 链接、图片、视频-----['link', 'image', 'video']
            ]
          },
          syntax:{
            highlight:text => hljs.highlightAuto(text).value
          }
        }

      }
    }
  },
  mounted() {


    getTaskDetail(this.task.id).then(res=>{
      this.task = res.data.data;

    })
  },
  methods:{
    saveTask(){
      this.titleEditMode=false;
      updateTask(this.task.id,this.task).then(res=>{
        if(res.data.code===200){
          this.$message.success("保存成功")
        }
      })
    }
  }

}
</script>

<style scoped>
@import "../../../assets/css/common.css";

.task-detail{
  height: 100%;
  display: flex;
  flex-direction: column;
}



.task-detail .header{
  padding: 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: solid 1px #ddd;
  margin-bottom: 20px;
  color: white;
  background: var(--headerBackground);
}

.header .back-btn{
  cursor: pointer;
  border-radius: 5px;
  padding: 10px 12px;
}

.back-btn:hover{
  background: rgba(255,255,255,0.1);
}

.task-detail .content{
  flex: 1;
  overflow-y: auto;
  position: relative;
}

.flex{
  justify-content: center;
}
.right-panel{
  width: 400px;

}

.right-panel .panel-container{
  position: sticky;
  text-align: left;
  top: 0;
}
.content .editor{
  min-height: 1200px;
  width: 800px;
  background: white;
  box-shadow: 0 0 3px 1px rgb(60 64 67 / 15%);
  margin-right: 20px;

}

.content .editor >>> .ql-container{
  height: calc(100% - 66px);
}
.content .editor >>> .ql-toolbar{
  position: sticky;
  top: 0;
  z-index: 1;
  background: white;
}

.footer{

  height: 40px;
  line-height: 40px;
}

.task-detail{
  background: #E9EEF3;
}

.panel{
  box-shadow: 0 0 3px 1px rgb(60 64 67 / 15%);
  margin-bottom: 20px;
}

.panel .panel-title{
  background: #ffca7c;
  padding: 5px;
  color: black;

}

.panel .panel-content{
  background: #ffe5ab;
  padding: 5px;
  font-size: 16px;
}


.panel-content >>> .el-checkbox__inner{
  width: 16px;
  height: 16px;
}

.panel-content >>> .el-checkbox__inner::after{
  top: 2px;
  left: 5px;
}

.panel-content >>> .el-checkbox__input.is-checked+.el-checkbox__label{
  text-decoration:line-through;
}

.panel-content >>> .el-checkbox__label{
  font-size: 16px;
}

</style>